<?php
namespace Business;
class ArticleModel {
    static function lists($pid,$per_page = 10) {
        $res = new \ArticleModel();
        $res = $res
            ->where('status',1);
        if ($pid) {
            $res = $res->where('parent_id',$pid);
        }
        $res = $res->paginate($per_page);
        if($res){
            $page = $res->toArray();
            $data['data']= $page['data'];
            unset($page['data']);
            $data['page']= $page;
        } else {
            $data = array();
        }
        return $data;

    }
    static function detail($aid) {
        $res = new \ArticleModel();
        $res = $res
            ->select(array('article.*','ac.content'))
            ->where('article.article_id',$aid)
            ->where('article.status',1)
            ->join('article_content as ac','ac.article_id','=','article.article_id')
            ->first();
        if ($res) {
            $data = $res->toArray();
        } else {
            $data = array();
        }
        return $data;
    }
}
